﻿using System;
using Aliyun.OSS.Common;

namespace Aliyun.OSS.Sdk.JSST
{
    /// <summary>
    /// 配置信息
    /// </summary>
    public class Config
    {
        /// <summary>
        /// 配置文件对象锁
        /// </summary>
        private static object objLock = new object();

        /// <summary>
        /// 是否已初始化
        /// </summary>
        public static bool IsIni = false;

        /// <summary>
        /// 账号
        /// </summary>
        public static string AccessKeyId ="";// "LTAIS8N6dUnTV2sS";

        /// <summary>
        /// 密码
        /// </summary>
        public static string AccessKeySecret ="";// "pFSVugeZyj6ecpH1u7YejlWtWWsUvN";

        /// <summary>
        /// 云服务地址
        /// </summary>
        public static string Endpoint = "";// "oss-cn-hangzhou.aliyuncs.com";

        /// <summary>
        /// 默认存储空间
        /// </summary>
        public static string BucketName = "";//"publicdata"; 

        //public static string DirToDownload = "<your local dir to download file>";

        /// <summary>
        /// 
        /// </summary>
        public static string FileToUpload = "";//"<your local file to upload>";

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="accessKeyId">账号</param>
        /// <param name="accessKeySecret">密码</param>
        /// <param name="endpoint">云服务地址</param>
        /// <param name="bucketName">（默认1个）存储空间</param>
        public static void Ini(string accessKeyId, string accessKeySecret, string endpoint, string bucketName = "publicdata")
        {
            lock (objLock)
            {
                IsIni = false;
                if (string.IsNullOrWhiteSpace(accessKeyId) == true)
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(accessKeySecret) == true)
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(endpoint) == true)
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(bucketName) == true)
                {
                    return;
                }
                Config.BucketName = bucketName;
                Config.AccessKeyId = accessKeyId;
                Config.AccessKeySecret = accessKeySecret;
                Config.Endpoint = endpoint;
                PutObjectHelp.Ini();
                IsIni = true;
            }

        }
    }
}